package Year22_Month03.day09;

import java.util.*;

public class Main2 {
    public int findMinimum(int n, int[] left, int[] right) {
        // write code here
        int sum = 0;//用来记录0的数量总和
        int leftSum = 0;
        int rightSum = 0;//用来记录左右手的总和
        int leftmin = 0;
        int rightmin = 0;//用来记录左右手的最小值。
        for (int i = 0; i < n; i++) {
            if(left[i] * right[i] == 0){
                //用来记录最小值
                sum =sum +  left[i] + right[i];
            }else{
                leftSum += left[i];
                rightSum += right[i];
                if(leftmin > left[i]){
                    leftmin = left[i];
                }
                if(rightmin > right[i]){
                    rightmin = right[i];
                }
            }
        }
        return sum + Math.min((leftSum - leftmin + 1),(rightSum - rightmin + 1)) + 1;
    }
}
